var form;
var layer;
//页面初始化时加载Layui框架
layui.use(['form', 'layer'], function () {
    form = layui.form();
    layer = layui.layer;
    //提交事件
    form.on('submit(submitButton)', function () {
        //提交按钮置为不可用
        $("#submit").addClass("layui-btn-disabled");
        pwdSet();
    });
});

function pwdSet() {
    var userId = $("#userId").val();
    var oldPass = $("#oldPass").val();
    var newPass = $("#newPass").val();
    var newConPass = $("#newConPass").val();

    var paramData = {
        'id': userId,
        'user.loginPass': newPass
    };

    var urlStr = basePath + "user/updatePwd.action";
    $.ajax({
        url: urlStr,
        type: "post",
        dataType: 'text',
        data: paramData,
        success: function (data) {
            if (data != null && data != "" && data == 0) {
                layer.confirm('密码修改成功，是否重新登陆？', {
                    title: " 确认",
                    icon: 6,
                    skin: 'layui-layer-molv',
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        parent.location.href = basePath + "logout.jsp";
                        layer.close(index);
                    }
                });
            } else {
                layer.open({
                    title: '错误',
                    icon: 5,
                    content: '密码修改失败!'
                });
            }
            //提交按钮置为可用
            $("#submit").removeClass("layui-btn-disabled");
        }
    });
}

// 原始密码
function oldPassBlur() {
    var userId = $("#userId").val();
    var oldPass = $("#oldPass").val();
    var paramData = {
        'id': userId,
        'user.loginPass': oldPass
    };
    var urlStr = basePath + "user/validatePwd.action";
    $.ajax({
        url: urlStr,
        type: "post",
        dataType: 'json',
        data: paramData,
        success: function (data) {
            if (data != null && data != "" && data == 1) {
                layer.open({
                    title: '错误',
                    icon: 5,
                    content: '密码错误!',
                    yes: function (index) {
                        $("#oldPass").focus();
                        layer.close(index);
                    }
                });
                return null;
            }
        }
    });
}

// 新密码
function newPassFocus() {
    var oldPass = $("#oldPass").val();
    if (oldPass == "") {
        $("#oldPass").focus();
    }
}